﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Items_AddEditCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            
        }
    }
    [System.Web.Services.WebMethod]
    public static void SaveItemCategory(ItemCategory category)
    {
        using (POSEntities db = new POSEntities())
        {
            try
            {
                category.BranchId = 1;
                category.EntryBy = 1;
                category.EntryDate = DateTime.Now;
                db.ItemCategories.Add(category);
                db.SaveChanges();
               
            }
            catch (Exception ex)
            {
               
            }

        }
    }
       [System.Web.Services.WebMethod]
    public static  List<ItemCategory> SearchCategories()
    {
        using (POSEntities db = new POSEntities())
        {
            try
            {
               var category = (from c in db.ItemCategories where c.IsDeleted == false select c).ToList();
                return category;
            }
            catch (Exception ex)
            {
                return null;
            }

        }
    }
      [System.Web.Services.WebMethod]
       public static void DeleteCategory(int id)
       {
           using (POSEntities db = new POSEntities())
           {
               try
               {
                   ItemCategory result = (from c in db.ItemCategories
                                    where c.CategoryId == id
                                    select c).SingleOrDefault();
                   result.IsDeleted = true;
                   db.SaveChanges();
                  
               }
               catch (Exception ex)
               {
                
               }

           }
       }
}